翻訳と辞書
Words near each other
・ "O" Is for Outlaw
・ "O"-Jung.Ban.Hap.
・ "Ode-to-Napoleon" hexachord
・ "Oh Yeah!" Live
・ "Our Contemporary" regional art exhibition (Leningrad, 1975)
・ "P" Is for Peril
・ "Pimpernel" Smith
・ "Polish death camp" controversy
・ "Pro knigi" ("About books")
・ "Prosopa" Greek Television Awards
・ "Pussy Cats" Starring the Walkmen
・ "Q" Is for Quarry
・ "R" Is for Ricochet
・ "R" The King (2016 film)
・ "Rags" Ragland
・ ! (album)
・ ! (disambiguation)
・ !!
・ !!!
・ !!! (album)
・ !!Destroy-Oh-Boy!!
・ !Action Pact!
・ !Arriba! La Pachanga
・ !Hero
・ !Hero (album)
・ !Kung language
・ !Oka Tokat
・ !PAUS3
・ !T.O.O.H.!
・ !Women Art Revolution


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

undefined behavior : ウィキペディア英語版
undefined behavior

In computer programming, undefined behavior (UB) is the result of executing computer code written in a programming language for which the language specification does not prescribe how that code should be handled. Undefined behavior is unpredictable and a frequent cause of software bugs.
The behavior of some programming languages—most famously C and C++—is undefined in some cases. In the standards for these languages, the semantics of certain operations are ''undefined''. An implementation is allowed to assume that such operations never occur in standard-conforming program code; the implementation will be considered correct whatever it does in such cases, analogous to don't-care terms in digital logic. This assumption can make various program transformations valid or simplify their proof of correctness, giving flexibility to the implementation. It is the responsibility of the programmer to write code that never invokes undefined behavior, although compiler implementations are allowed to issue diagnostics when this happens.
For example, in C the use of any automatic variable before it has been initialized yields undefined behavior, as does division by zero or indexing an array outside of its defined bounds (see buffer overflow). In general, any instance of undefined behavior leaves the abstract execution machine in an unknown state, and any subsequent behavior is also undefined. If it is not required that the compiler diagnose undefined behavior, programs invoking undefined behavior may compile and run producing correct results, incorrect results, or have any other behavior. Because of this, undefined behavior can create errors that are difficult to detect.
Under some circumstances there can be specific restrictions on undefined behavior. For example, the instruction set specifications of a CPU might leave the behavior of some forms of an instruction undefined, but if the CPU supports memory protection then the specification will probably include a blanket rule stating that no user-accessible instruction may cause a hole in the operating system's security; so an actual CPU would be permitted to corrupt user registers in response to such an instruction, but would not be allowed to, for example, switch into supervisor mode.
In C and C++, ''implementation-defined behavior'' is also used, where the language standard does not specify the behavior, but the implementation must choose a behavior and document and observe its rules. These standards also use ''unspecified behavior'' to mean that from a given set of possibilities it is not specified which behavior an implementation must choose, it need not document the choice or even be consistent, but it must choose one possibility.
In the C community, undefined behavior may be humorously referred to as "nasal demons", after a comp.std.c post that explained undefined behavior as allowing the compiler to do anything it chooses, even "to make demons fly out of your nose".〔(【引用サイトリンク】url=http://catb.org/jargon/html/N/nasal-demons.html )
== Examples in C and C++ ==

Attempting to modify a string literal causes undefined behavior:〔ISO/IEC (2003). ''ISO/IEC 14882:2003(E): Programming Languages - C++ §2.13.4 String literals ()'' para. 2〕

char
*p = "wikipedia"; // ill-formed C++11, deprecated C++98/C++03
p() = 'W'; // undefined behavior

One way to prevent this is defining it as an array instead of a pointer.

char p = 'W';

Integer division by zero results in undefined behavior:〔ISO/IEC (2003). ''ISO/IEC 14882:2003(E): Programming Languages - C++ §5.6 Multiplicative operators ()'' para. 4〕

int x = 1;
return x / 0; // undefined behavior

Certain pointer operations may result in undefined behavior:〔ISO/IEC (2003). ''ISO/IEC 14882:2003(E): Programming Languages - C++ §5.7 Additive operators ()'' para. 5〕

int arr() = ;
int
*p = arr + 5; // undefined behavior

Reaching the end of a value-returning function (other than main()) without a return statement may result in undefined behavior:

int f()
/
* undefined behavior
*/

The original ''The C Programming Language'' book cites the following examples of code which “can (and does) produce different results on different machines” (which could be considered just ''unspecified'' or ''implementation-defined behavior'' in today's terms):

printf("%d %d\n", ++n, power(2, n)); /
* WRONG
*/


a() = i++;

The later ANSI C standard chose to leave similar constructions ''undefined'', e.g. “This paragraph renders undefined statement expressions such as i = ++i + 1; while allowing i = i + 1;”.〔ANSI X3.159-1989 ''Programming Language C'', footnote 26〕

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「undefined behavior」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.